Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 Search this book:
Previous | Table of Contents | Next
Click on the OK button to close the Project Properties dialog box. Next, use the Properties window to set the class properties. Only two of the properties concern us for this project; the settings and an explanation of each follow: • Instancing MultiUse—This setting permits other clients (outside the project) to create instances of the class, with multiple instances (if requested) supplied by a single running copy of the server. The other possible settings of this property set different restrictions on the class, but these do not concern us at present. • Name AXDEMO—You can use any descriptive name here. This property is used to identify the class. It is displayed in other applications’ Object Browser dialog boxes and is used in code (as we’ll see later) to create an instance of the class. Once the class module’s properties are set, we can add the declarations of the variables that will be the class’s properties. You accomplish this in the General Declarations section of the class module. Here’s the code:
    Option Explicit
    Private pObjName As Variant
    Private pDateCreated As Date
    Private pNumber As Double
    Private pSquareRoot As Double
    Private pCubeRoot As Double
The Option Explicit statement should already be present, placed there automatically by Visual Basic. If not, you need to select Options from the Tools menu; on the Editor tab, turn on the Require Variable Declarations option. Lacking the Option Explicit statement in a module, Visual Basic does not require variables to be declared—a definite invitation to errors. If you examine these variable declarations, you’ll see that all of them are Private, meaning they are not accessible outside the ActiveX server. They can be used for purely internal uses by the class, or they can be exposed to clients as properties (for reading, writing, or both) by means of property procedures. When you expose a variable with a property procedure, it becomes one of the object’s properties that can be accessed by clients. We need to take a short detour from the demonstration project to explore property procedures. First, however, save the project. I used the default names suggested by Visual Basic: MyTestAXDLL for the project and AXDEMO for the class module (class modules are automatically given the .CLS extension). #### Property Procedures You had an introduction to property procedures in Chapter 6; now the time has come to learn more. Property procedures are a central part of ActiveX server programming. While you may be able to create very simple servers without using property procedures, you’ll find them essential for most of your projects. You can use a property procedure to create standard read/write properties that can be both read and set by clients. These procedures also permit you to create read-only properties, perform some action when the property is read or set, or assign a Help topic to the property. Property procedures come in three varieties. Property Get and Property Let are usually used in tandem, permitting the client to read and set, respectively, the value of a property in the ActiveX object. Property Set is used in place of Property Let when the property in question contains a reference to an object. Because the demonstration server does not use object reference properties, I’ll limit the discussion to Property Get and Property Let. Let’s assume we want the object to hav